list1 = [[0, 1, 0, 0],
         [1, 1, 1, 0],
         [0, 1, 0, 0],
         [1, 1, 0, 0]]


def panduan(x, y, list2):
    sum = 0
    # 左边界
    if x - 1 > 0:
        if list2[x - 1][y] == 0:
            sum += 1
    if x - 1 == 0:
        sum += 1
    # 上边界
    if y - 1 > 0:
        if list2[x][y - 1] == 0:
            sum += 1
    if y - 1 == 0:
        sum += 1

    # 右边界
    if x + 1 < len(list2[0]):
        if list2[x + 1][y] == 0:
            sum += 1
    if x + 1 == len(list2[0]):
        sum += 1
    # 下边界
    if y + 1 < len(list2):
        if list2[x][y + 1] == 0:
            sum += 1
    if y + 1 == len(list2):
        sum += 1

    return sum


sum1 = 0
for i in range(len(list1)):
    for j in range(len(list1[0])):
        if list1[i][j] == 1:
            print(i, j)
            print('-->', i + j)
            sum1 += panduan(i, j, list1)
print(sum1)
